package com.example.icampusevent;

import com.example.icampusevent.jsonobjects.*;

import java.util.ArrayList;

import android.app.Activity;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

public class EventListAdapter extends BaseAdapter{
	
	private Activity activity;
	private ArrayList<TimeQueryEvent> eventList;
	
	public EventListAdapter(Activity _activity, ArrayList<TimeQueryEvent> _eventList) {
        activity = _activity;
        eventList = _eventList;
    }
	
	public int getCount() {
		return eventList.size();
	}

	public TimeQueryEvent getItem(int position) {
		return eventList.get(position);
	}

	public long getItemId(int position) {
		return eventList.get(position).getId();
	}

	public View getView(int position, View convertView, ViewGroup parent) {
		 View vi = convertView;
		 if(convertView==null) {
			 LayoutInflater inflater = (LayoutInflater)activity.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
			 vi = inflater.inflate(R.layout.event_list_row_layout, null);
		 }
		 
         TextView title = (TextView)vi.findViewById(R.id.title);
         TextView location = (TextView)vi.findViewById(R.id.location);
         TextView time = (TextView)vi.findViewById(R.id.time);
 
         // Setting all values in listview
         title.setText(eventList.get(position).getTitle());
         location.setText(eventList.get(position).getLocation());
         time.setText(eventList.get(position).getStart());
         return vi;
	}
}
